var app = getApp()
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

//网络连接工具类
function netWorkUtil(ApiName,paraData, cb) {
  requestApiForPost(ApiName, paraData, cb)
}
//调用API 统一方法
function requestApiForPost(ApiName, PostData, cb) {
  wx.request({
    url: getApp().globalData.serverUrl+ ApiName,
    header: {
      'content-type': 'application/json'
      },
    data: PostData,
    method: 'POST',
    success: function (res) {
      typeof cb == "function" && cb(null, res)
    },
    fail: function () {
      typeof cb == "function" && cb(res)
    }
  })
}
module.exports = {
  formatTime: formatTime,
  netWorkUtil: netWorkUtil
}
